/**
 * Initialize your data structure here.
 */
/*
用两个队列来实现栈 队列的特点是先进先出 栈的特点是先进后出
设定一个队列为主队列 设定一个队列为辅助队列
* */
var MyStack = function() {
    // 设定主队列
    this.queue = []
    // 辅助队列
    this._queue = []
};

/**
 * Push element x onto stack.
 * @param {number} x
 * @return {void}
 */
// 入栈操作的时候 将主队列的内容导入辅助队列 然后将入栈的元素放入主队列队头的位置 再将辅助队列的内容依次添加到主队列
MyStack.prototype.push = function(x) {
    this.queue.push(x)
};

/**
 * Removes the element on top of the stack and returns that element.
 * @return {number}
 */
MyStack.prototype.pop = function() {
    while(this.queue.length > 1) {
        this._queue.push(this.queue.shift())
    }
    let ans = this.queue.shift()
    while (this._queue.length) {
        this.queue.push(this._queue.shift())
    }
    return ans
};
/**
 * Get the top element.
 * @return {number}
 */
MyStack.prototype.top = function() {
    return this.queue.slice(-1)[0]
};
/**
 * Returns whether the stack is empty.
 * @return {boolean}
 */
MyStack.prototype.empty = function() {
    return !this.queue.length
};

/**
 * Your MyStack object will be instantiated and called as such:
 * var obj = new MyStack()
 * obj.push(x)
 * var param_2 = obj.pop()
 * var param_3 = obj.top()
 * var param_4 = obj.empty()
 */
